package com.herench.bs.handler;

import com.herench.bs.agent.IHospitalAgent;
import com.herench.bs.agent.IOutpatientClinicAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ThinkPad on 2017/9/5.
 */

@Component
@Handler(code = "100709",name="查询医生排班简化视图")
public class DoctorAppointSchedulingHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String startDate = requestMessage.getArgsPropertyStringValue("startDate");
        String endDate = requestMessage.getArgsPropertyStringValue("endDate");
        if(endDate.equals("2018-01-02")){
            endDate="2019-01-02";
        }
        if(endDate.equals("2018-01-03")){
            endDate="2019-01-03";
        }
        if(endDate.equals("2018-01-04")){
            endDate="2019-01-04";
        }
        if(endDate.equals("2018-01-05")){
            endDate="2019-01-05";
        }
        if(endDate.equals("2018-01-06")){
            endDate="2019-01-06";
        }
        if(endDate.equals("2018-01-07")){
            endDate="2019-01-07";
        }
        String deptCode = requestMessage.getArgsPropertyStringValue("deptId");
        String doctorCode = requestMessage.getArgsPropertyStringValue("docId");
        String schDate = requestMessage.getArgsPropertyStringValue("schDate");
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);
        IOutpatientClinicAgent outpatientClinicAgent = getCleverClinicContext().getApplicationContext().getBean(IOutpatientClinicAgent.class);
        Map<String,Object> res = outpatientClinicAgent.loadDoctorScheduling(channelCode,hospitalCode,deptCode,doctorCode,schDate,startDate,endDate);
        IHospitalAgent hospitalAgent = getCleverClinicContext().getApplicationContext().getBean(IHospitalAgent.class);
        Map<String,Object> params = new HashMap<>();
        params.put("hospitalCode",hospitalCode);
        params.put("deptCode",deptCode);
        Map<String,Object> deptMap = hospitalAgent.loadDeptsByConditions(params);

//        params.put("deptCode",deptCode);
        params.put("innerCode",doctorCode);
        Map<String,Object> docMap = hospitalAgent.loadDoctorByConditions(params);
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
